#include "Examen.h"

Data::Data(){
this->zi=1;
this->luna=1;
this->an=2012;
}
Data::Data(int zi, int luna, int an)
{
this->zi=zi;
this->luna=luna;
this->an=an;
}
int Data::getZi()
{
return this->zi;
}
int Data::getLuna()
{
return this->luna;
}
int Data::getAn()
{
return this->an;
}
void Data::setZi(int zi)
{
this->zi=zi;
}
void Data::setLuna(int luna)
{
this->luna=luna;
}
void Data::setAn(int an)
{
this->an=an;
}
bool Data::anBisect()
{
int an_curent;
an_curent=this->an;
if (an_curent%4==0) return true;
else return false;
}
int Data::checkZile(int luna)
{
switch(luna)
{
case 1: return 31;
	break;
case 2: {if(this->anBisect())
	return 29;
	else return 28;
	}
case 3: return 31;
	break;
case 4: return 30;
	break;
case 5: return 31;
	break;
case 6: return 30;
	break;
case 7: return 31;
	break;
case 8: return 31;
	break;
case 9: return 30;
	break;
case 10: return 30;
	break;
case 11:return 31;
	break;
case 12:return 31;
	break;
}
}
int Data::difZile(Data d)
{
int dif=0, an1,an2,luna1,luna2,zi1,zi2,i,ad=0,zd=0,lc,k;
an1=this->getAn();
an2=d.getAn();
luna1=this->getLuna();
luna2=d.getLuna();
zi1=this->getZi();
zi2=d.getZi();
if (an1>an2) 
{
ad=an1-an2-1;
if (luna1>luna2) ad++;
if (luna1==luna2 && zi1>zi2) ad++;	
}
if (an1<an2)
{
ad=an2-an1-1;
if(luna1<luna2) ad++;
if (luna1==luna2 && zi2<=zi1) ad++;
}
if (luna1>luna2) {
lc=luna2;
while (lc<=luna1)
{
if (lc==luna2) i=zi1;
else i=1;
if (lc==luna1) k=0;
while (i<=this->checkZile(lc) && k!=0) { ++zd; i++;};
++lc;
} 
}
else if (luna1<luna2)
{
lc=luna1;
while (lc<=luna2)
{
if (lc==luna1) i=zi2;
else i=1;
if (lc==luna2) k=0;
while (i<=this->checkZile(lc) && k!=0) { ++zd; i++;};
++lc;
}
}
else zd=abs(zi2-zi1);
dif=ad*365 + zd;
return dif;
}
bool Data::operator>=(Data d)
{
int an1,an2,zi1,zi2,luna1,luna2;
an1=this->getAn();
an2=d.getAn();
luna1=this->getLuna();
luna2=d.getLuna();
zi1=this->getZi();
zi2=d.getZi();
if (an1>an2) return false;
if ((an1==an2)&&(luna1>luna2)) return false;
if ((an1==an2)&&(luna1==luna2)&&(zi1>zi2)) return false;
return true;
}
ostream& operator<<(ostream& afiseaza, const Data& d)
{
afiseaza<<d.zi<<"/"<<d.luna<<"/"<<d.an;
return afiseaza;
}
Examen::Examen()
{
this->materie="NULL";
}
Examen::Examen(Data d, string materie)
{
this->d=d;
this->materie=materie;
}
Data Examen::getData()
{
return this->d;
}
void Examen::setData(Data d)
{
this->d=d;
}
string Examen::getMaterie()
{
return this->materie;
}
ostream& operator<<(ostream& scrie, const Examen& ex)
{
int k;
scrie<<"Data:"<<ex.d<<" | Materie:"<<ex.materie<<endl;
return scrie;
}
Examene::Examene(Examen ex[100])
{
for(int i=0;i<100 && ex[i].getMaterie()!="NULL";i++)
this->ex[i]=ex[i];
}
void Examene::afiseaza()
{
for (int i=0;i<100 && this->ex[i].getMaterie()!="NULL";i++) cout<<ex[i];
}
int Examene::getNrExamene()
{ 
int i=0;
while ( this->ex[i].getMaterie()!="NULL") ++i;
return i;
}
void Examene::ordoneaza()
{
Examen aux;
int i,j,k=this->getNrExamene();
for(i=0;i<k-1;i++)
for(j=i+1;j-k;j++)
{
if(this->ex[j].getData()>=this->ex[i].getData())
{
aux=this->ex[i];
this->ex[i]=this->ex[j];
this->ex[j]=aux;
}
}
}
int Examene::zileMin()
{
int min,min1,k=this->getNrExamene();
Data d1=this->ex[0].getData();
Data d2=this->ex[1].getData();
min=d1.difZile(d2);
for(int i=1;i<k-1;i++) 
{
d1=this->ex[i].getData();
d2=this->ex[i+1].getData();
min1=d1.difZile(d2); 
if (min1<min) min=min1;
}
return min;
}
